package com.fau.wm.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 药品-储位 中间表
 * @author liy
 * @datetime 2014年8月4日,下午9:25:20
 */
@Entity
@Table(name = "medical_medicine_position")
public class MedicalMedicinePosition implements Serializable ,JSONAware {

	private static final long serialVersionUID = -4051109820530702953L;
	
	private String id;
	
	private MedicalMedicine medicine;			// 关联药品
	private MedicalLayerPosition layerPosition; 	// 储位
	
	
	private String medicalId;
	private String positionId;
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Transient
	public String getMedicalId() {
		return medicalId;
	}
	
	public void setMedicalId(String medicalId) {
		this.medicalId = medicalId;
	}
	
	@Transient
	public String getPositionId() {
		return positionId;
	}
	
	public void setPositionId(String positionId) {
		this.positionId = positionId;
	}

	@ManyToOne
	@JoinColumn(name = "medical_id")
	public MedicalMedicine getMedicine() {
		return medicine;
	}

	public void setMedicine(MedicalMedicine medicine) {
		this.medicine = medicine;
	}

	@ManyToOne
	@JoinColumn(name = "position_id")
	public MedicalLayerPosition getLayerPosition() {
		return layerPosition;
	}

	public void setLayerPosition(MedicalLayerPosition layerPosition) {
		this.layerPosition = layerPosition;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("warehouseCode", layerPosition.getShelfLayer().getShelf().getWarehouse().getCode());
		obj.put("warehouseName", layerPosition.getShelfLayer().getShelf().getWarehouse().getName());
		obj.put("shelf", layerPosition.getShelfLayer().getShelf().getShelfNum());
		obj.put("shelfLayer", layerPosition.getShelfLayer().getLayerNum());
		obj.put("position", layerPosition.getPositionNum());
		return obj.toString();
	}

	
}
